﻿using System.Data;
using System.IO;
using DataScripter.Database.SqlServer;
using DataScripter.Scripting.OutputDestinations;

namespace DataScripter.Scripting.Output.Sql.SqlServer
{
    public class InsertOutputProducer : SqlServerOutputProducer
    {
        public InsertOutputProducer(IOutputDestination container) : base(container)
        {
        }

        protected override void HandleRecord(IDataReader reader, StreamWriter streamWriter, bool isFirstRecord)
        {
            ScriptTableNamePkFound(TableScriptRequest, reader, streamWriter);
            ScriptSpecialFieldTreatments(TableScriptRequest, reader, streamWriter, OutputContext, OutputDestination.Resolve<SqlServerDb>());
            streamWriter.WriteLine(ProduceInsertSqlForCurrentRecord(TableScriptRequest, reader, isFirstRecord));
        }

    }
}